package com.ah.suams.controller;

import com.ah.suams.bean.Member;
import com.ah.suams.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MemberController {
    @Autowired
    private MemberService memberService;

    @RequestMapping("/member")
    @ResponseBody
    public Member member(String id){
        Member member = memberService.member(id);
        return member;
    }

    @RequestMapping("/memberList")
    public String memberList(String id, String name, String deptName, Model model){
        List<Member> memberList = memberService.memberList(id,name,deptName);

        model.addAttribute("memberList",memberList);

        return "member";
    }

    @RequestMapping("/addMember")
    public String addMember(String id,String password,String name,
                            String sex,String birthday,String jointime,
                            String phone,String email,String deptName,String jobName){
        memberService.addMember(id,password,name,sex,birthday,jointime,phone,email,deptName,jobName);
        return "redirect:/memberList";
    }

    @RequestMapping("/updateMember")
    public String updateMember(String id,String password,String name,
                               String sex,String birthday,String jointime,
                               String phone,String email,String deptName,String jobName){
        memberService.updateMember(id,password,name,sex,birthday,jointime,phone,email,deptName,jobName);
        return "redirect:/memberList";
    }

    @RequestMapping("/deleteMember")
    public String deleteMember(String id){
        memberService.deleteMember(id);
        return "redirect:/memberList";
    }

}
